export default class Rcon {
    constructor(port, password) {
        this.URL = `ws://202.189.12.253:${port}/${password}`
    }
    isConnected(ws) {
        return ws.readyState == 1
    }
    send(text) {
        let ws = new WebSocket(this.URL)
        ws.onopen = () => {
            ws.send(JSON.stringify({
                Identifier: 1000,
                Message: text,
                Name: 'WebRcon'
            }))
        }
        ws.onmessage = (evt) => {
            let jsonData = JSON.parse(evt.data)
            if (jsonData.Identifier == 1000) {
                ws.onopen = function () { }
                ws.onmessage = function () { }
                ws.close()
                ws = null
            }
        }
    }
    reloadPlugin(name) {
        this.send(`o.reload "${name}"`)
    }
}